import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

import '../../res/theme.dart';
import '../common/utils.dart';

void easyLoadingInit() {
  EasyLoading.instance
    ..displayDuration = const Duration(milliseconds: 1000)
    ..indicatorType = EasyLoadingIndicatorType.squareCircle
    ..indicatorSize = 25.0
    ..loadingStyle = EasyLoadingStyle.custom
    ..indicatorColor = AppTheme.mainColor
    ..radius = 12.0
    ..dismissOnTap = false
    ..textColor = const Color(0xFF333333)
    ..backgroundColor = Colors.white
    ..textStyle = const TextStyle(
        color: Color(0xFF333333),
        fontSize: 14.0,
        fontWeight: FontWeight.normal)
    ..animationStyle = EasyLoadingAnimationStyle.scale
  //遮罩样式
    ..maskType = EasyLoadingMaskType.black
  //背景是否可点击
    ..userInteractions = false;
}

bool isLoading() {
  return EasyLoading.isShow;
}

void showLoading() {
  Utils.hideKeyBoard();
  if (!EasyLoading.isShow) {
    EasyLoading.show();
  }
}

void hideLoading() {
  if (EasyLoading.isShow) {
    EasyLoading.dismiss();
  }
}